#e[Player]
#ScriptVersion[2]
#Menu[STATE]
#Text[]
#ReplayName[th_psy]

script_player_main
{
	let current		=GetCurrentScriptDirectory();
	let imgpsy		=current~"psy.png";
	let imgrate		=current~"rate.png";
	let shot1		=current ~ "shot1.wav";
	let shotCount		=-1;
	let bNextShot		=false;
	let sw_shotCount	=-1;
	let sw_bNextShot	=false;
	let ix			=GetClipMinX;
	let mx			=GetClipMaxX;
	let iy			=GetClipMinY;
	let my			=GetClipMaxY;
	let S			=0;
	let sp			=0;
	let S1			=0;
	let swx			=0;
	let swy			=0;
	let sw_r		=0;
	let swa			=0;
	let swb			=0;
	let p1			=0;
	let p2			=0;
	let p3			=0;
	let p4			=0;
	let sw_g		=120;
	let AlphaCount		=255;
	let A1			=0;
	let B1			=0;
	let D1			=0;
	let k1			=0;
	let k2			=0;
	let k3			=0;
	let k4			=0;
	let moji		=0;
	let moji1		=0;
	let moji2		=0;
	let moji3		=0;
	let moji4		=0;
	let moji5		=0;
	let moji6		=0;
	let moji01		=0;
	let moji02		=0;
	let moji03		=0;
	let moji04		=0;
	let moji05		=0;
	let moji06		=0;
	let dc			=0;
	let ppp			=0;
	let p			=0;
	let jiki		=0;
	let JIKI		=0;
	let kaif		=0;
	let bk			=0;

	@Initialize
	{	
		SetPlayerLifeImage(imgpsy, 1, 5, 49, 60);
		LoadGraphic(imgpsy);
		LoadGraphic(imgrate);
		LoadSE(shot1);
		//SetAutoEffect(false);
		SetRebirthFrame(0);
		LoadPlayerShotData(current~"psyShotData.txt");
		GetCommonData(jiki);
		mojii;
	}


		function RealToIntString(let num){
		if(num<0){num=0;}
		let stringarray=["0","1","2","3","4","5","6","7","8","9"];
		let lp=floor(log10(num))+1;
		let lp1=lp;
		if(lp<=0){result="0"}
		else{
		result = "";
		loop(lp){
		result=result~ stringarray[(num%(10^lp1)-num%(10^(lp1-1)))/(10^(lp1-1))];
		lp1--;
		}
		}
		}
	let A=0;
	let B=0;
		let Anl=270;
		let Anr=270;
		let Anll=0;
		let Anrr=0;
	@MainLoop
	{
	let Angl=157.5;
	let Angr=157.5;
	if(GetCommonData(jiki)==1){
	SetSpeed(3.5,2.5);
	}
	if(GetCommonData(jiki)==2){
	SetSpeed(4,2.5);
	}
	if(GetCommonData(jiki)==3){
	SetSpeed(3,2.5);
	}


		//悳ppxvZƂ
		if(GetCommonData(jiki)==2){
		if(GetKeyState(VK_RIGHT)==KEY_HOLD&&Anl<270+90){
		Anrr+=0.5;
		Anl+=0.5;
		}
		else{
		if(Anl>270){
		Anrr-=1;
		Anl-=1;
		}
		}
		if(GetKeyState(VK_LEFT)==KEY_HOLD&&Anr>270-90){
		Anll-=0.5;
		Anr-=0.5;
		}
		else{
		if(Anr<270){
		Anll+=1;
		Anr+=1;
		}
		}
		}

	swx=GetPlayerX+cos(sw_r+270)*40;
	swy=GetPlayerY+sin(sw_r+270)*40;
	swa=GetGapAngle(GetPlayerX,GetPlayerY,swx,swy);
		if(ppp>0){ppp--;}
		S++;

		k1=cos(10*(S/3))*24;
		k2=sin(10*(-S/3))*18;
		k3=sin(10*(S/3))*18;
		k4=cos(10*(S/3))*4;
			sp=0.32;
		if((GetKeyState(VK_BOMB)==KEY_PUSH)&&sw_shotCount==-1)
		{
		if(GetCommonData(jiki)==1){
		if(sw_g>=0){
		kai(40);
		sw_g-=4;
		}
		}
		if(GetCommonData(jiki)==2){
		if(sw_g>=0){
		kai(20);
		sw_g-=2;
		}
		}
		if(GetCommonData(jiki)==3){
		if(sw_g>=0){
		kai(80);
		sw_g-=3;
		}
		}
		}
		if((GetKeyState(VK_BOMB)==KEY_HOLD||sw_bNextShot==true)&&sw_shotCount==-1)
		{
		if(GetCommonData(jiki)==1){
		if(sw_g>=0){sw_g-=1.6;}
		}
		if(GetCommonData(jiki)==2){
		if(sw_g>=0){sw_g-=1.8;}
		}
		if(GetCommonData(jiki)==3){
		if(sw_g>=0){sw_g-=1.2;}
		}
		}
		else {
		if(sw_g<=100&&kaif==1){
		if(GetCommonData(jiki)==1){
		sw_g+=0.3;
		}
		if(GetCommonData(jiki)==2){
		sw_g+=0.6;
		}
		if(GetCommonData(jiki)==3){
		sw_g+=0.25;
		}
		}
		if(sw_g>100){
		sw_g=100;
		}
		if(sw_g<0){
		sw_g=0;
		}
		}
		
		if((GetKeyState(VK_BOMB)==KEY_PUSH || GetKeyState(VK_BOMB)==KEY_HOLD || sw_bNextShot==true) && sw_shotCount==-1)
		{
			sw_shotCount = 0;
			sw_bNextShot = false;
		}
		if(GetKeyState(VK_BOMB)==KEY_HOLD && sw_shotCount>0)
		{
			sw_bNextShot = true;
		}
			if(sw_shotCount%3 == 0)
			{
			if(sw_g>=1){
	PlaySE(shot1);
	if(GetCommonData(jiki)==1){
			loop(4){
			A+=90;
			Shot_j(swx+cos(2.5*S+A)*28+4,swy+sin(2.5*S+A)*28,22,swa+sin(2.5*S+A-sw_r-270)*8,5);
			Shot_j(swx+cos(2.5*S+A)*28-4,swy+sin(2.5*S+A)*28,22,swa+sin(2.5*S+A-sw_r-270)*8,5);
			}
	}
	if(GetCommonData(jiki)==2){
			A=157.5;
			loop(4){
			A+=45;
			Shot_j(GetPlayerX+cos(A)*24,GetPlayerY+sin(A)*24-10,22,270,5);
			}
	}
	if(GetCommonData(jiki)==3){
			A=195;
			loop(4){
			A+=30;
			B=A;
			loop(3){
			B+=120;
			Shot_j(GetPlayerX+cos(A)*64+(cos(B)*20),GetPlayerY+sin(A)*48+(sin(B)*20)+10,22,A,5);
			}
			}
	}
			}
			}
		if(sw_shotCount >= 0)
		{
			sw_shotCount++;
		}
		if(sw_shotCount == 2)
		{
			sw_shotCount=-1;
		}


		if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD || bNextShot==true) && shotCount==-1)
		{
			shotCount = 0;
			bNextShot = false;
		}
		if(GetKeyState(VK_SHOT)==KEY_HOLD && shotCount>0)
		{
			bNextShot = true;
		}

		let ttt=k4;
			if(shotCount%3 == 0)
			{
	if(GetCommonData(jiki)==1){
			CreatePlayerShot01(GetPlayerX(), GetPlayerY(), 25, 270, sp, 3, 4);
			CreatePlayerShot01(GetPlayerX()+k1-k3, GetPlayerY()-k2-10, 24, 270+ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()-k1+k3, GetPlayerY()+k2-10, 24, 270-ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()+k1+k3, GetPlayerY()-k2-10, 24, 270+ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()-k1-k3, GetPlayerY()+k2-10, 24, 270-ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()+k1, GetPlayerY()-k2-10, 24, 270+ttt, sp, 4, 3);
			CreatePlayerShot01(GetPlayerX()-k1, GetPlayerY()+k2-10, 24, 270-ttt, sp, 4, 3);
	}
	if(GetCommonData(jiki)==2){
			CreatePlayerShot01(GetPlayerX(), GetPlayerY(), 25, 270, sp, 3, 4);
			loop(4){
			Angr+=45;
			Angl+=45;
			CreatePlayerShot01(GetPlayerX+50+cos(Angr+Anrr)*20,GetPlayerY+30+sin(Angr+Anrr)*20,24,Anl,sp+0.1,4,3);
			CreatePlayerShot01(GetPlayerX-50+cos(Angl+Anll)*20,GetPlayerY+30+sin(Angl+Anll)*20,24,Anr,sp+0.1,4,3);
			}
	}
	if(GetCommonData(jiki)==3){
			CreatePlayerShot01(GetPlayerX(), GetPlayerY(), 25, 270, sp+0.5, 3, 4);
			CreatePlayerShot01(GetPlayerX()+35, GetPlayerY, 24, 270, sp+0.1, 4, 3);
			CreatePlayerShot01(GetPlayerX()-35, GetPlayerY, 24, 270, sp+0.1, 4, 3);
			CreatePlayerShot01(GetPlayerX()+25, GetPlayerY, 24, 270, sp+0.1, 4, 3);
			CreatePlayerShot01(GetPlayerX()-25, GetPlayerY, 24, 270, sp+0.1, 4, 3);
	}
		}
		
		if(shotCount >= 0)
		{
			shotCount++;
		}
		if(shotCount == 2)
		{
			shotCount=-1;
		}
		SetGrazeCircle(48);
		SetIntersectionCircle(GetPlayerX,GetPlayerY,1);

	yield;
	}

task kai(t){
loop(t){
yield;
kaif=0;
}
kaif=1;
}

task mojii{
loop{
	moji01=ppp;
	moji1=moji01;
	if(moji1>9){
	moji01=0;
	}

	moji02=ppp;
	moji2=truncate(moji02/10);
	if(moji2>9){
	moji02=0;
	}

	moji03=ppp;
	moji3=truncate(moji03/100);
	if(moji3>9){
	moji03=0;
	}

	moji04=ppp;
	moji4=truncate(moji04/1000);
	if(moji4>9){
	moji04=0;
	}

	moji05=ppp;
	moji5=truncate(moji05/10000);
	if(moji5>9){
	moji05=0;
	}

	moji06=ppp;
	moji6=truncate(moji06/100000);
	if(moji6>9){
	moji06=0;
	}
yield;
}
}


task Shot_j(x,y,speed,angle,bullet){

	let obj_js=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj_js,x);
	Obj_SetY(obj_js,y);
	Obj_SetSpeed(obj_js,speed);
	Obj_SetAngle(obj_js,angle);
	ObjShot_SetGraphic(obj_js,bullet);
	ObjShot_SetDamage(obj_js,0.4);
	ObjShot_SetPenetration(obj_js,8);
	loop{
	if(Obj_GetY(obj_js)<iy||Obj_GetX(obj_js)<ix||Obj_GetX(obj_js)>mx){
	Obj_Delete(obj_js);
	break;
	}
	DeleteEnemyShotToItemInCircle(SHOT,Obj_GetX(obj_js),Obj_GetY(obj_js),12);
	if(GetEnemyShotCountEx(Obj_GetX(obj_js),Obj_GetY(obj_js),16,ALL)>0){
	ppp+=GetEnemyShotCountEx(Obj_GetX(obj_js),Obj_GetY(obj_js),16,ALL);
	DeleteEnemyShotToItemInCircle(SHOT,Obj_GetX(obj_js),Obj_GetY(obj_js),12);
	AddScore(ppp);
	ObjShot_SetGraphic(obj_js,7);
	Obj_SetSpeed(obj_js,3);
	Obj_SetAngle(obj_js,angle+rand(12,-12));
	ObjShot_SetDamage(obj_js,0.2);
	ObjShot_SetPenetration(obj_js,20);
	loop(2){
	yield;
	DeleteEnemyShotToItemInCircle(SHOT,Obj_GetX(obj_js),Obj_GetY(obj_js),6);
	}
	yield;
	yield;
	Obj_Delete(obj_js);
	return;
	}
	yield;
	}


}

function GetGapAngle(
	let xA,
	let yA,
	let xB,
	let yB
){
	return atan2( yB - yA, xB - xA );
}

	@SpellCard
	{
	}
	


	let hdn=0;
	let hdn1=0;


	@DrawLoop
	{
	let swo=0;
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetGraphicAngle(0,0,0);
		if(GetKeyState(VK_LEFT)==KEY_PUSH||GetKeyState(VK_LEFT)==KEY_HOLD)
		{
		if(GetCommonData(jiki)==1){
			SetGraphicRect(1, 133, 49, 188);
			}
		if(GetCommonData(jiki)==2){
			SetGraphicRect(175, 45, 196, 90);
			}
		if(GetCommonData(jiki)==3){
			SetGraphicRect(140, 45, 175, 90);
			}
		}
		else if(GetKeyState(VK_RIGHT)==KEY_PUSH||GetKeyState(VK_RIGHT)==KEY_HOLD)
		{
		if(GetCommonData(jiki)==1){
			SetGraphicRect(1, 69, 49, 124);
			}
		if(GetCommonData(jiki)==2){
			SetGraphicRect(175, 90, 196, 136);
			}
		if(GetCommonData(jiki)==3){
			SetGraphicRect(140, 90, 175, 136);
			}
		}
		else 
		{
		if(GetCommonData(jiki)==1){
			SetGraphicRect(1, 5, 49, 60);
			}
		if(GetCommonData(jiki)==2){
			SetGraphicRect(175, 0, 196, 45);
			}
		if(GetCommonData(jiki)==3){
			SetGraphicRect(140, 0, 175, 45);
			}
		}
		DrawGraphic(GetPlayerX(), GetPlayerY());

		//IvV
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetGraphicAngle(0,0,S*2);
	if(GetCommonData(jiki)==1){
		SetGraphicRect(100, 100, 117, 117);
		DrawGraphic(GetPlayerX+k1, GetPlayerY-k2-10);
		DrawGraphic(GetPlayerX-k1, GetPlayerY+k2-10);
	}
	if(GetCommonData(jiki)==2){
		SetGraphicRect(100, 140, 117, 157);
		DrawGraphic(GetPlayerX+50,GetPlayerY+20);
		DrawGraphic(GetPlayerX-50,GetPlayerY+20);
	}
	if(GetCommonData(jiki)==3){
		SetGraphicRect(100, 120, 117, 137);
		DrawGraphic(GetPlayerX+30, GetPlayerY);
		DrawGraphic(GetPlayerX-30, GetPlayerY);
	}

		//TuEF|
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(0.8,0.8);
		SetAlpha(120);
		SetGraphicAngle(0,0,S*3);
	if(GetCommonData(jiki)==1){
		swo=0;
		loop(4){
		swo+=90;
		SetGraphicRect(100, 100, 117, 117);
		DrawGraphic(swx+cos(2.5*S+swo)*28,swy+sin(2.5*S+swo)*28);
		}
	}
	if(GetCommonData(jiki)==2){
		swo=157.5;
		loop(4){
		swo+=45;
		SetGraphicRect(100, 140, 117, 157);
		DrawGraphic(GetPlayerX+cos(swo)*24,GetPlayerY+sin(swo)*24-10);
		}
	}
	if(GetCommonData(jiki)==3){
		swo=195;
		loop(4){
		swo+=30;
		SetGraphicRect(100, 120, 116, 136);
		DrawGraphic(GetPlayerX+cos(swo)*64,GetPlayerY+sin(swo)*48+10);
		}
	}

		//
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetGraphicAngle(S*4+90,0,-45);
		SetGraphicRect(100, 160, 125, 185);
		DrawGraphic(GetPlayerX, GetPlayerY);
		SetColor(255, 255, 255);
		SetRenderState(ALPHA);
		SetTexture(imgpsy);
		SetGraphicScale(1,1);
		SetAlpha(255);
		SetGraphicAngle(0,S*4,45);
		SetGraphicRect(100, 160, 125, 185);
		DrawGraphic(GetPlayerX, GetPlayerY);



	loop(10){
	B1=S+D1;
	A1=sin(B1);
	if(A1>0&&sin(B1*2)>0){
	SetGraphicRect(96,0,140,44);
	SetRenderState(ALPHA);
	SetGraphicScale(1.3*A1,1.3*A1);
	SetAlpha((70*sin(B1*2)));
	SetGraphicAngle(0,0,D1);
	SetTexture(imgpsy);
	DrawGraphic(GetPlayerX, GetPlayerY);
	}
	D1+=36;
	}



	if(GetPlayerX>ix+110||GetPlayerY<my-80){AlphaCount=255;}
	else{AlphaCount=80;}
//̕ӃJE^֌W

	//ꌅ

	SetGraphicRect(0+moji1*10,60,10+moji1*10,80);
	SetRenderState(ALPHA);
	SetGraphicScale(1,1);
	SetAlpha(AlphaCount);
	SetGraphicAngle(0,0,0);
	SetTexture(imgrate);
	DrawGraphic(ix+85,my-40);
	//
	SetGraphicRect(0+moji2*10,60,10+moji2*10,80);
	SetRenderState(ALPHA);
	SetGraphicScale(1,1);
	SetAlpha(AlphaCount);
	SetGraphicAngle(0,0,0);
	SetTexture(imgrate);
	DrawGraphic(ix+75,my-40);
	//O
	SetGraphicRect(0+moji3*10,60,10+moji3*10,80);
	SetRenderState(ALPHA);
	SetGraphicScale(1,1);
	SetAlpha(AlphaCount);
	SetGraphicAngle(0,0,0);
	SetTexture(imgrate);
	DrawGraphic(ix+65,my-40);
	//l
	SetGraphicRect(0+moji4*10,60,10+moji4*10,80);
	SetRenderState(ALPHA);
	SetGraphicScale(1,1);
	SetAlpha(AlphaCount);
	SetGraphicAngle(0,0,0);
	SetTexture(imgrate);
	DrawGraphic(ix+55,my-40);
	//܌
	SetGraphicRect(0+moji5*10,60,10+moji5*10,80);
	SetRenderState(ALPHA);
	SetGraphicScale(1,1);
	SetAlpha(AlphaCount);
	SetGraphicAngle(0,0,0);
	SetTexture(imgrate);
	DrawGraphic(ix+45,my-40);
	//Z
	SetGraphicRect(0+moji6*10,60,10+moji6*10,80);
	SetRenderState(ALPHA);
	SetGraphicScale(1,1);
	SetAlpha(AlphaCount);
	SetGraphicAngle(0,0,0);
	SetTexture(imgrate);
	DrawGraphic(ix+35,my-40);

	if(sw_g<=9){DrawText(""~RealToIntString(sw_g)~"",ix+13,my-22,16,AlphaCount);}
	else if(sw_g<=99&&sw_g>=10){DrawText(""~RealToIntString(sw_g)~"",ix+9,my-22,16,AlphaCount);}
	else if(sw_g>=100){DrawText(""~RealToIntString(sw_g)~"",ix+4,my-21,15.5,AlphaCount);}
	SetGraphicRect(28,0,57,14);
	SetAlpha(AlphaCount);
	SetTexture(imgrate);
	SetGraphicAngle(0,0,0);
	if(sw_g/50<=2){
	SetGraphicScale(sw_g/50,1);
	}
	else{
	SetGraphicScale(2,1);
	}
	DrawGraphic(ix+32+29*(sw_g/100),my-11);
	SetGraphicRect(0,20,91,44);
	SetGraphicScale(1,1);
	SetAlpha(AlphaCount);
	SetTexture(imgrate);
	SetGraphicAngle(0,0,0);
	DrawGraphic(ix+48,my-15);

	if(sw_g<1){
	SetGraphicRect(0,49,37,61);
	SetGraphicScale(1,1);
	SetAlpha(AlphaCount);
	SetTexture(imgrate);
	SetGraphicAngle(0,0,0);
	DrawGraphic(ix+60,my-11);
	}

	}


	
	@Finalize
	{
		DeleteGraphic(imgpsy);
	}
}
